<?php
// require_once 'Zend/Loader.php';
// Zend_Loader::registerAutoload();
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
/* Front Controller - Bootstrap */

define ( 'DS', DIRECTORY_SEPARATOR );
define ( 'PS', PATH_SEPARATOR );
define ( 'BASEPATH', getcwd () . DS );

error_reporting(E_ALL|E_STRICT); 
ini_set ( 'display_startup_errors', 1 );
ini_set ( 'display_errors', 1 );

setlocale(LC_ALL, 'BRA');
date_default_timezone_set('America/Sao_Paulo');

/****** Seta INCLUDE_PATH *******/
/*
set_include_path ( '.' . PS . BASEPATH . 'library' . DS . 
PS. BASEPATH . 'application/classes'.
PS . BASEPATH . 'application/classes/Forms' .
PS . BASEPATH . 'application/classes/Autenticacao' . 
PS . BASEPATH . 'application/classes' . PS . 
DS . get_include_path () );

*/

set_include_path ('.' . PS . BASEPATH . 'library' . DS .
PS. BASEPATH . 'application/classes' . PS .
BASEPATH . 'application/models' . PS .
DS . get_include_path() );


/****** Carrega a configura��o no formato XML *******/
$config = new Zend_Config_Xml ( 'application/config/config.xml', 'config' );
$db = Zend_Db::factory ( $config->db->adapter, $config->db->toArray () );
Zend_Db_Table_Abstract::setDefaultAdapter ( $db );
Zend_Registry::set('config',$config);

/****** Inicia a sess�o ******/
Zend_Session::start ();
$session = new Zend_Session_Namespace ( $config->session->namespace );
if (isset ( $config->session->timeout ))
	$session->setExpirationSeconds ( $config->session->timeout * 60 );

/********** Carrega e inicia a classe manipuladora de Layout ***********/
Zend_Loader::loadClass ( 'Zend_Layout' );
Zend_Layout::startMvc ();

/* Configura��es padr�es da vis�o */
$view = Zend_Layout::getMvcInstance ()->getView ();
$view->baseUrl = '/textando';
$view->publicUrl = '/textando/public';
$view->setEncoding ( 'UTF-8' );

$view->setEscape ( 'HTMLEntities' );

/************** ADICIONA OS MODULOS **************/
$frontController = Zend_Controller_Front::getInstance ();

$frontController->setDefaultModule("default");

$module_dir = 'application';
$defaultModules = array (
'default' => BASEPATH . $module_dir . DS . 'controllers'
);
$frontController->setDefaultModule("default");
$frontController->addModuleDirectory(BASEPATH . $module_dir);
$frontController->setBaseUrl($view->baseUrl);

$frontController->setControllerDirectory ( $defaultModules);

$frontController->throwExceptions ( true );

/* Adicionar tratador de erros */
$frontController->registerPlugin ( new Zend_Controller_Plugin_ErrorHandler ( ) );

try { 
$auth = Zend_Auth::getInstance(); 
$acl = new Autenticacao_MyACL($db);
//$plugin = new Autenticacao_MyPluginAuth($auth, $acl);
//$frontController->registerPlugin( $plugin );
$frontController->setParam('acl', $acl);
$frontController->setParam('auth', $auth);
} catch ( Zend_Db_Exception $e) {
print $e->getMessage();
}

/* OK, fa�a acontecer, front controller */
$frontController->dispatch ();

?>
